package com.eqdd.yiqidian.ui.CreateSpace;

import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.eqdd.yiqidian.CreateSpaceActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.adapter.MyFragmentPagerAdapter;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.ui.CreateSpace.Fragment.CreateSpaceFragment;
import com.gyf.barlibrary.ImmersionBar;

import java.util.ArrayList;
import java.util.List;

/**
 * @author吕志豪 .
 * @date 17-12-28  下午3:00.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class CreateSpaceActivity extends BaseActivity {
    List<Fragment> mFragments;

//    @Override
//    public void onWindowFocusChanged(boolean hasFocus) {
//        super.onWindowFocusChanged(hasFocus);
//        if (hasFocus && Build.VERSION.SDK_INT >= 21) {
//            View decorView = getWindow().getDecorView();
//            decorView.setSystemUiVisibility(
////                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
//                             View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
////                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                             |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
////                            | View.SYSTEM_UI_FLAG_FULLSCREEN
////                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
//            );
////            getWindow().setNavigationBarColor(0x00009688);

//        }
//    }

    List<String> mTitles = new ArrayList<>();
    private CreateSpaceActivityCustom dataBinding;
    private ImmersionBar immersionBar;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_create_space);
        immersionBar = ImmersionBar.with(this);
        immersionBar
                .transparentBar()
                .fullScreen(true)
                .fitsSystemWindows(true)
                .init();


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (immersionBar != null) {
            immersionBar.destroy();
        }

    }

    @Override
    public void initData() {
        mTitles.add("主页");
        mTitles.add("微博123123123123");
        mTitles.add("相册");
        mTitles.add("相册1231231231231");
        mTitles.add("相册");
        mTitles.add("相册123123123131");
        mTitles.add("相册");
        setupViewPager();
        dataBinding.ivHead.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            System.out.println(bottom);
        });
        dataBinding.appbarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
            System.out.println(verticalOffset);
        });
    }

    @Override
    public void setView() {

    }

    private void setupViewPager() {
        setupViewPager(dataBinding.viewpager);
        dataBinding.slidingTabStrip.setViewPager(dataBinding.viewpager);
    }

    private void setupViewPager(ViewPager viewPager) {
        mFragments = new ArrayList<>();
        for (int i = 0; i < mTitles.size(); i++) {
            CreateSpaceFragment yueFragment = new CreateSpaceFragment();
            Bundle bundle = new Bundle();
            bundle.putString(Config.URL, HttpConfig.YUE_USER_ARTICLE_LIST);
            yueFragment.setArguments(bundle);
            mFragments.add(yueFragment);
        }
        viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), mTitles, mFragments));
    }
}
